{{--注册 模板--}}
@extends('web.main')
@section('content')
<div class="dbody">
    <div class="center plate">
        <div class="pTitle">
            <a href="javascript:;" class="click">登陆</a>
            <a href="/web/register/noval">注册</a>
        </div>
        <div style="height:10px;"></div>
        <div style="height:10px;"></div>
        <div class="pInput">
            <input type="text" onkeyup="checkPhone();" id="mobile" placeholder="请输入您的手机号">
        </div>
        <div class="pInput">
            <input type="text" onkeyup="numberSum();" id="password" placeholder="请输入您的密码">
        </div>
        <div class="pInput">
            <a href="login2.html" style="float:left;">验证码登陆</a>
            <a href="pwd.html" style="float:right;">忘记密码？</a>
        </div>
        <div style="height:10px;"></div>
        <div class="pInput">
            <input type="button" id="submit" onclick="setSubmit()" value="登陆">
        </div>
        <div class="pInput">
            <p class="agree">还没账号？<a href="/web/register/noval">立即注册</a></p>
        </div>
        <div style="height:20px;"></div>
    </div>
</div>

<div id="webPop"></div>
<a href="">url</p>
<script src="../../pc/js/cache.js"></script>
<script type="application/javascript">
    $( function(){
        //cacheDel("pcUserInfo");
        var pcUserInfo = cacheGet("pcUserInfo");//取登录后用户缓存
        console.log(pcUserInfo);
        if(pcUserInfo!=null){
            var preview = pcUserInfo.preview;
            getWebPop("即将跳转到下一页",'',0);
                            setTimeout(function(){
                            window.location.href = preview;
                        }, 1000 * 2);
        }
        
    } );
    //发送验证码
    var phoneFlag = false;
    var passwordFlag = false;
    function sendYzm(){
        getWebPop('功能待完善！','',0);
    }
    
    function checkPhone(){
        var phone = $("#mobile").val();
        var regx = new RegExp("^1[0-9]{10}$");
        if(regx.test(phone)){
            phoneFlag = true;
        }else{
            phoneFlag = false;
        }
        
    }
    
    //验证手机号码符合格式
    function validPhone(phone){
        var regx = new RegExp("^1[0-9]{10}$");
        if(!regx.test(phone)){
            //$("#error").text("请输入正确的手机号码");
            getWebPop("请输入正确的手机号码!",'',0);
            phoneFlag = false;
        }else{
            phoneFlag = true;
        }
    }
    //
    var showNumber = 0;//设置显示提示次数
    function numberSum(){
        var sumValue = $("#password").val();
        if(sumValue.length<5){
            passwordFlag = false;
            if(showNumber==0){
                
                getWebPop('密码长度必须大于等于5！','',0);//显示一次提示，zwp
            }
            showNumber++;//提示取消
        }else{
            passwordFlag = true;
        }
    }
    
    
    function validPassword(pwd){
        if(pwd.length==0){
            passwordFlag = false;
            getWebPop('请输入正确的密码，至少5位！','',0);
            return;
        }
            var regx = new RegExp("^[0-9a-zA-Z_]{5,20}$");//密码验证规则
            if(!regx.test(pwd)){
                passwordFlag = false;
                getWebPop('密码格式不对，请输入5-20位数字/字母/符号','',0);
            }else{
                passwordFlag = true;
            }
        
    }
    //页面跳转
    function setSubmit(){
        var phone = $("#mobile").val();
        var pwd = $("#password").val();
        validPassword(pwd);
        validPhone(phone);
        
        if(phoneFlag&&passwordFlag){
            var data = {
                phone:phone,
                pwd:pwd,
                app_access:web_access
            };
            $.ajax({
                type:"post",
                data:data,
                url:"/api/web/user/login",
                success:function(res){
                    if(res.code==200){
                        console.log(res.data);
                        var token = res.data.token;
                        var type = res.data.type;
                        var cate = res.data.cate;
                        var preview = "index";
                        var pcUserInfo = {
                            token:token,
                            type:type,
                            cate:cate,
                            preview:preview
                    };
                    cacheSet('pcUserInfo',pcUserInfo);
                        getWebPop('即将跳转到下一页！','',0);
                        setTimeout(function(){
                            window.location.href = 'index';
                        }, 1000 * 2);
                    }else{
                        getWebPop(res.message,'',0);
                    }
                },
                error:function(){
                    getWebPop('提交失败','',0);
                }
            });
        }
        
        
        
        
        
    }
</script>
@stop